package quq.missq.fragments;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.android.volley.VolleyError;

import java.util.HashMap;
import java.util.Map;

import quq.missq.Constants;
import quq.missq.R;
import quq.missq.adapter.GoddessPagerAdapter;
import quq.missq.beans.GoddessBean;
import quq.missq.utils.VolleyTool;
import quq.missq.views.VerticalViewPager;

/**
 * Created by River on 7/24/15.
 */
public class GoddessFragment extends Fragment implements VolleyTool.HTTPListener{

    private RelativeLayout mFragmentLayout;
    private VerticalViewPager mVerticalViewPager;
    private GoddessPagerAdapter mPagerAdapter;

    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
        super.onCreateView(inflater, container, savedInstanceState);
        mFragmentLayout = (RelativeLayout)inflater.inflate(R.layout.three_fragment, container,false);
        initView();
        initViewData();
        loadNetworkData();
        return mFragmentLayout;
    }

    private void initView(){
        mVerticalViewPager = (VerticalViewPager)mFragmentLayout.findViewById(R.id.verticalViewPager);
    }

    private void initViewData(){
        mPagerAdapter = new GoddessPagerAdapter(getActivity());
    }

    private void loadNetworkData(){
        Map<String,String> params = new HashMap<>();
        params.put("pn","0");
        params.put("maxResults","50");
        VolleyTool.get(getActivity(), Constants.GET_GODDESS_URL,params,this,Constants.GET_GODDESS, GoddessBean.class);
    }

    @Override
    public <T> void onResponse(T t, int requestCode) {
        GoddessBean gb = (GoddessBean)t;
        mPagerAdapter.setData(gb.getData().getResults());
        mVerticalViewPager.setAdapter(mPagerAdapter);
    }

    @Override
    public void onErrorResponse(VolleyError error, int requestCode) {

    }
}
